<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <script type="text/javascript" src="../../inc/ctx.jsp"></script>
        <script type="text/javascript" src="../js/g.js"></script>
        <script type="text/javascript" src="http://cdn.uuola.cn/js/formvalid.js" charset="utf-8"></script>
        <script type="text/javascript" src="../js/channeltype.js"></script>
        <link href="../css/com.css" type="text/css" rel="stylesheet"/>
        <style>
            img.s1{width:100px;border:1px #EFEFEF solid;padding:1px;}
            #panel{width:950px;}
            #panel table{width:940px;}
            span.s1{color:#B1B1B1;}
            #submitBtn{width:150px;height:35px;}
        </style>
    </head>
    <body>

        <div id="panel">
            <form id="addFrm" name="addFrm">
                <table>
                    <tr>
                        <th colspan="3">添加Word</th>
                    </tr>
                    <tr>
                        <td class="r">所属板块：</td>
                        <td>
                            <script>out_select('channeltype');</script>
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">信息类别：</td>
                        <td>
                            <span id="ctp_name_path"> 请选择信息类别 </span>
                            <input type="button" value="选择类别" onclick="selectCatelogs();"/> *
                            <input type="hidden" name="cid" id="cid" value="" />
                            <input type="hidden" name="ctp" id="ctp" value=""  valid="required" errmsg="信息分类不能为空!" />
                        </td>
                        <td><div id="err_ctp"></div></td>
                    </tr>
                    <tr>
                        <td width="180" height="27" class="r">WORD：</td>
                        <td width="49%">
                            <input name="word" type="text" id="word" tabindex="1" size="50" maxlength="32" valid="required" errmsg="关键词不能为空!" />* 
                    </td>
                        <td width="34%"><div id="err_word"><span class="s1">热词.30个字符内.勿使用特殊字符.</span></div></td>
                    </tr>
                    <tr>
                      <td class="r">发布时间：</td>
                      <td><input type="text" name="_pubtime" maxlength="19" id="_pubtime" tabindex="5">
                        <input type="button" value="" class="calendar"   onClick="cdpn('_pubtime');"/>
                      <input type="hidden" value="" name="pubtime" id="pubtime"/></td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">截止时间：</td>
                        <td><input name="_stoptime" type="text" id="_stoptime" tabindex="5" maxlength="19"/>
                        <input type="button" value="" class="calendar"   onClick="cdpn('_stoptime');"/>
                      <input type="hidden" value="" name="stoptime" id="stoptime"/>
                      </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td class="r">GOTOURL：</td>
                      <td><label for="gotourl"></label>
                        <textarea name="gotourl" cols="55" rows="10" style="width:360px;height:100px;" id="gotourl" valid="required|limit" min="1" max="512" errmsg="GOTOURL不能为空!|字符数控制在512内"></textarea>
                      *</td>
                      <td><div id="err_gotourl"><span class="s1">跳转地址，512个字符,http://开头</span></div></td>
                    </tr>
                     <tr>
                        <td class="r">排序：</td>
                        <td>
                            <input name="ordernum" type="text" id="ordernum" tabindex="5" value="" maxlength="17"></td>
                        <td><span class="s1">此默认值是依据当前表中最大排序+1得出</span></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><input type="hidden" name="channeltype" id="channeltype" value="" /></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">&nbsp;</td>
                        <td class="c"><input name="submitBtn" type="button" class="button medium orange" id="submitBtn" tabindex="7" value="添加" onClick="Word.submit();" /></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td class="c"></td>
                        <td>&nbsp;</td>
                    </tr>
                </table>
            </form>
        </div>



        <script type="text/javascript">
            var frm = ut.e('addFrm');
            initValid(frm);
            var Word ={
                submit:function(){
                    if(!convertData()){
                        return;
                    }
                    if(validator(frm)){
                        $.post('../app/hotword/save.shtm',ut.getFormData('#addFrm'),function(x){
                            if($.trim(x)=='ok'){
                                ut.m('添加成功!');
                                ut.reload('?t='+ut.r()+'&channeltype='+$('#channeltype').val());
                            }else{
                                ut.m('添加失败. '+x);
                            }   
                        });
                    }
                }
            };     

            function convertData(){
                var _pt = $('#_pubtime').val();
                var _et = $('#_stoptime').val();
                var t1=0 , t2=0;
                if(va.datetime(_pt)){
                    t1 = ut.parseMs(_pt) ;
                }
                if(va.datetime(_et)){
                    t2 =  ut.parseMs(_et) ;
                }
                if(t2>0 && t2<t1){
                    ut.m('结束时间必须大于发布时间.');
                    return false;
                }
                if(t1>0)$('#pubtime').val(t1);
                if(t2>0)$('#stoptime').val(t2);
                return true;
            };

            function selectCatelogs(){
                  var ct = $('#channeltype').val();
                if(!va.mint(ct)){
                    TxBox.alert('请先选择板块.');
                    return;
                }
                TxBox.winpop(250,350,'类目选择', 'catalogs_select_pop.html?channeltype='+$('#channeltype').val());
            };

            function reloadCatData(cid,ctp){
                $('#cid').val(cid);
                $('#ctp').val(ctp);
                $('#ctp_name_path').text(cid+';'+ctp);
                TxBox.closeWinpop();
            };

            function changeChannelType(){
                $('#ctp_name_path').text('请选择信息类别 ');
                $('#cid').val('');
                $('#ctp').val('');
            };

            function initOrderNum(){
                $.get('../app/hotword/query_max_ordernum.shtm?t='+ut.r(),function(x){
                    $('#ordernum').val((Number($.trim(x))+1));
                });
            };
            
            jQuery(function(){
                $('#channeltype').val('3');
                $('#channeltype').change(function(){
                    changeChannelType();
                    if($('#channeltype').val()!='3'){
                        $('#channeltype').val('3');
                    }
                });
                initOrderNum();
            });
        </script>
    </body>
</html>
